<%--
  User: yangtao
  Date: 2017/6/5
  Time: 14:46
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%
    String path = request.getContextPath();
%>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="<%=path%>/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="<%=path%>/css/global.css">
    <script type="text/javascript" src="<%=path %>/plugins/jquery.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/core/helper.js"></script>
    <script src="<%=path%>/plugins/layui/layui.js"></script>
    <script type="text/javascript" src="<%=path%>/js/core/building_utils.min.js?v=10"></script>
</head>

<body>
<div class="layui-tab layui-tab-brief" lay-filter="tableFilter">
    <ul class="layui-tab-title">
        <li class="layui-this" lay-id="tab1">内容录制</li>
        <li lay-id="tab2">内容列表</li>
        <li lay-id="tab3">分配内容</li>
        <li lay-id="tab4">已分配内容</li>
        <c:if test="${isCheck == true}">
            <li lay-id="tab5">内容审核</li>
        </c:if>
    </ul>
    <div class="layui-tab-content" style="padding: 0px; margin-top: 5px;">
        <div class="layui-tab-item layui-show">
            <form id="form" class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">资源名称</label>
                    <div class="layui-input-inline">
                        <select name="type_code" id="type_code" lay-filter="type_code">
                            <option value="-1" selected="selected">无</option>
                            <c:forEach var="root" items="${roots}">
                                <option value="${root.type_code}">${root.type_name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">资源类型</label>
                    <div class="layui-input-inline">
                        <select name="customType" id="customType" lay-filter="customType">
                            <option value="default" selected="selected">默认</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input name="title" id="title" lay-verify="title" placeholder="请输入资源标题"
                               autocomplete="off" class="layui-input" type="text">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <input name="description" id="description" lay-verify="description" placeholder="请输入资源描述"
                               autocomplete="off" class="layui-input" type="text">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">内容地址</label>
                    <div class="layui-input-block">
                        <input name="content_url" id="content_url" lay-verify="content_url" placeholder="请输入资源描述"
                               autocomplete="off" class="layui-input" type="text">
                    </div>
                </div>

                <div id="perms">
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">资源图标</label>
                    <div class="layui-input-block"
                         style="background: #FFFFFF;padding: 20px;border:1px solid #e6e6e6;">
                        <div align="center" style="width: 210px;height: 160px;">
                            <div class="center"
                                 style="width: 210px;height: 120px; margin-bottom: 8px; border:1px solid #fde7e5; padding: 2px">
                                <img id="LAY_demo_upload" style="max-height:100%; max-width:100%;"
                                     src="<%=path%>/pic/upload_ioc.png"/>
                            </div>
                            <input type="hidden" id="icon_url" name="icon_url" lay-verify="icon_url"/>
                            <input type="file" name="file" class="layui-upload-file" lay-title="选择一张图片">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <button id="savebt" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="submitComm">
                        新增保存
                    </button>
                </div>
            </form>
        </div>

        <div class="layui-tab-item">
            <form class="layui-form layui-form-pane" style="min-height: 50%">
                <label class="layui-form-label">资源类型</label>
                <div class="layui-input-inline">
                    <select name="tab2_type_code" id="tab2_type_code" lay-filter="tab2_type_code">
                        <option value="-1" selected="selected">无</option>
                        <c:forEach var="root" items="${roots}">
                            <option value="${root.type_code}">${root.type_name}</option>
                        </c:forEach>
                    </select>
                </div>

                <table class="layui-table">
                    <colgroup>
                        <col width="250">
                        <col width="200">
                        <col>
                        <col>
                        <col width="150">
                    </colgroup>
                    <thead>
                    <tr>
                        <th>图片</th>
                        <th>标题</th>
                        <th>描述</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="resourceList"></tbody>
                </table>
                <div style="float:right;margin-right:1px;" id="resourcePage"></div>
            </form>
        </div>

        <div class="layui-tab-item">
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">资源类型</label>
                    <div class="layui-input-inline" style="float:left;">
                        <select name="tab3_type_code" id="tab3_type_code" lay-filter="tab3_type_code">
                            <option value="-1" selected="selected">无</option>
                            <c:forEach var="root" items="${roots}">
                                <option value="${root.type_code}">${root.type_name}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div style="color:red;">
                        <strong style="color:blue;">Tips：</strong> 默认分配全部资源（包括默认资源），如果有不需要的请去掉勾选。
                    </div>
                </div>

                <div class="table-responsive">
                    <table class="layui-table"
                           style="table-layout: fixed; word-wrap: break-word;" cellpadding="0"
                           cellspacing="0">
                        <colgroup>
                            <col width="250">
                            <col>
                            <col>
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th>图片</th>
                            <th>标题</th>
                            <th>描述</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="assignsList"></tbody>
                    </table>
                </div>
                <div id="assignsPage" style="float:right;margin-right:1px;"></div>

                <table class="layui-table">
                    <colgroup>
                        <col>
                        <col>
                        <col width="150">
                    </colgroup>
                    <thead>
                    <tr>
                        <th>小区编号</th>
                        <th>小区名</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="commBody"></tbody>
                </table>
                <button style="float:left;margin-right:1px;" class="layui-btn layui-btn-normal" type="button"
                        onclick="fixAssigns()">确定分配
                </button>
                <div style="float:right;margin-right:1px;" id="commPage"></div>
            </form>
        </div>

        <div class="layui-tab-item">
            <form class="layui-form layui-form-pane" action="" style="min-height: 50%">
                <label class="layui-form-label">小区</label>
                <div class="layui-input-inline" style="float:left;margin-right:1px;">
                    <select name="selectSeparateComm" id="selectSeparateComm" lay-filter="selectSeparateComm">
                        <option value="">请请选小区</option>
                    </select>
                </div>
                <label class="layui-form-label">资源类型</label>
                <div class="layui-input-inline">
                    <select name="tab4_type_code" id="tab4_type_code" lay-filter="tab4_type_code">
                        <option value="-1" selected="selected">无</option>
                        <c:forEach var="root" items="${roots}">
                            <option value="${root.type_code}">${root.type_name}</option>
                        </c:forEach>
                    </select>
                </div>

                <table class="layui-table">
                    <colgroup>
                        <col width="250">
                        <col width="250">
                        <col>
                        <col>
                        <col width="200">
                    </colgroup>
                    <thead>
                    <tr>
                        <th>图片</th>
                        <th>标题</th>
                        <th>描述</th>
                        <th>内容地址</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="alreadyAssignsList"></tbody>
                </table>
                <div style="float:right;margin-right:1px;" id="alreadyAssignsPage"></div>
            </form>
        </div>
        <c:if test="${isCheck == true}">
            <div class="layui-tab-item">
                <form class="layui-form layui-form-pane" style="min-height: 50%">
                    <label class="layui-form-label">资源类型</label>
                    <div class="layui-input-inline">
                        <select name="tab5_type_code" id="tab5_type_code" lay-filter="tab5_type_code">
                            <option value="-1" selected="selected">无</option>
                            <c:forEach var="root" items="${roots}">
                                <option value="${root.type_code}">${root.type_name}</option>
                            </c:forEach>
                        </select>
                    </div>

                    <table class="layui-table">
                        <colgroup>
                            <col width="250">
                            <col width="250">
                            <col>
                            <col>
                            <col width="200">
                        </colgroup>
                        <thead>
                        <tr>
                            <th>图片</th>
                            <th>标题</th>
                            <th>描述</th>
                            <th>内容地址</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="checkList"></tbody>
                    </table>
                    <div style="float:right;margin-right:1px;" id="checkPage"></div>
                </form>
            </div>
        </c:if>
    </div>
</div>
<script>
    var form, customTypeList;
    layui.use(['form', 'tree', 'laypage', 'upload', 'element'], function () {
        form = layui.form();
        var element = layui.element();
        var reg = /^[A-Za-z]+$/;
        var isUrl = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
        form.on('select(type_code)', function (data) {
            $('#perms').empty();
            var roots = eval('(' + '${roots}' + ')');
            for (var i in roots) {
                var root = roots[i];
                if (data.value === root.type_code) {
                    if (root.customContentId != null && "undefined" != typeof  root.customContentId) {
                        var param = {};
                        param.isPage = false;
                        param.isAnalysisCustomContent = true;
                        param.customTypeId = root.customContentId;
                        postJson("<%=path%>/cms/resource/queryCustomTypeList.x", $.param(param), function (data) {
                            $('#customType').empty();
                            customTypeList = data.data.list;
                            for (var i in customTypeList) {
                                $("#customType").append('<option value="' + customTypeList[i].custom_type_code + '">' + customTypeList[i].custom_type_name + '</option>');
                                if (i == 0) {
                                    customAddPerms(customTypeList[i].custom_type_code);
                                }
                            }
                            form.render('select');
                        });
                    } else {
                        $('#customType').empty();
                        $("#customType").append('<option value="default" selected="selected">默认</option>');
                        customAddPerms('default');
                        form.render('select');
                    }
                }
            }
        });

        form.on('select(customType)', function (data) {
            customAddPerms(data.value);
        });

        form.on('select(tab2_type_code)', function (data) {
            var typeCode;
            if ('-1' === data.value) {
                typeCode = 'appContent';
            } else {
                typeCode = data.value;
            }
            queryResourceList(resourceParam('tab2', typeCode, 1));
        });

        form.on('select(tab3_type_code)', function (data) {
            var typeCode;
            if ('-1' === data.value) {
                typeCode = 'appContent';
            } else {
                typeCode = data.value;
            }
            queryResourceList(resourceParam('tab3', typeCode, 1));
        });

        form.on('select(tab4_type_code)', function (data) {
            queryResourceList(resourceParam('tab4', null, 1));
        });

        form.on('select(tab5_type_code)', function (data) {
            var typeCode;
            if ('-1' === data.value) {
                typeCode = 'appContent';
            } else {
                typeCode = data.value;
            }
            queryResourceList(resourceParam('tab5', typeCode, 1));
        });

        form.on('select(selectSeparateComm)', function (data) {
            queryResourceList(resourceParam('tab4', null, 1));
        });

        form.on('checkbox(selectRemoveResource)', function (data) {
            var resourceId = data.value;
            if (data.elem.checked == false) {
                removeResources.push(resourceId);
            } else {
                var j = -1;
                for (var i in removeResources) {
                    if (removeResources[i] == resourceId) {
                        j = i;
                        break;
                    }
                }
                if (j != -1) {
                    removeResources.splice(j, 1);
                }
            }
        });

        layui.upload({
            url: '<%=path%>/cms/resource/uploadFile.x?isTemp=' + true
            , success: function (res) {
                LAY_demo_upload.src = res.data.imageUrl;
                $('#icon_url').val(res.data.imagePath);
            }
        });

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 2) {
                    return '标题至少得2个字符!';
                }
            },
            description: function (value) {
                if (value.length < 2) {
                    return '描述至少得2个字符!';
                }
            }
            , icon_url: function (value) {
                if (value.length < 5) {
                    return '必须选择图片！';
                }
            }
            , content_url: function (value) {
                if (value.length != 0 && !isUrl.test(value)) {
                    return '内容地址不是正确的Url！';
                }
            }
        });

        //监听Tab切换，以改变地址hash值
        element.on('tab(tableFilter)', function () {
            if (this.getAttribute('lay-id') == "tab2") {
                queryResourceList(resourceParam('tab2', null, 1));
            } else if (this.getAttribute('lay-id') == "tab3") {
                clearAssignsTab();
                queryResourceList(resourceParam('tab3', null, 1));
            } else if (this.getAttribute('lay-id') == "tab4") {
                separateSelectComm(true, function () {
                    queryResourceList(resourceParam('tab4', null, 1));
                });
            } else if (this.getAttribute('lay-id') == "tab5") {
                queryResourceList(resourceParam('tab5', null, 1));
            }
        });

        //小区添加提交
        form.on('submit(submitComm)', function (data) {
            var typeCode = $("select[name='type_code']").val();
            var resourcesSort = $("select[name='resourcesSort']").val();
            if (typeCode == -1) {
                layer.msg('必须选择资源类型！', {icon: 5});
                return false;
            }
            if (resourcesSort == -1) {
                layer.msg('必须选择操作类型！', {icon: 5});
                return false;
            }
            postJson("<%=path%>/cms/resource/saveResource.x", $('#form').serialize(), function (data) {
                parent.layer.msg('录制成功，请等待审核。', {icon: 6});
                clearRecordTab();
            });
            return false;
        });
    });

    function customAddPerms(customTypeCode) {
        $('#perms').empty();
        for (var i in customTypeList) {
            if (customTypeCode === customTypeList[i].custom_type_code) {
                var customContents = customTypeList[i].customContents;
                for (var j in customContents) {
                    var customContent = customContents[j];
                    var dsCustomDescribe;
                    if (customContent != null && customContent.customType === 'CMS_CUSTOM_SORT') {
                        var sortListView = '';
                        if (customContent.customDescribe != null && "undefined" != typeof customContent.customDescribe) {
                            dsCustomDescribe = ' value = "' + customContent.customDescribe + '"';
                        } else {
                            dsCustomDescribe = ' value = "" ';
                        }

                        if (customContent.spinnerMap) {
                            for (var key in customContent.spinnerMap) {
                                sortListView += '<option value="' + key + '">' + customContent.spinnerMap[key] + '</option>'
                            }
                        } else {
                            sortListView = '<option value="-1">无</option>'
                        }

                        $("#perms").append(
                            '<div  class="layui-form-item">' +
                            '<label class="layui-form-label">' + customContent.customName + '</label>' +
                            '<div class="layui-inline">' +
                            '<input type="hidden" name="customKeys" value ="' + customContent.customKey + '"/>' +
                            '<select name="customValues">' + sortListView + '</select>' +
                            '<input type="hidden" id="customDescribes" name="customDescribes" ' + dsCustomDescribe + '/>' +
                            '</div>' +
                            '</div>'
                        );
                    } else if (customContent != null) {
                        if (customContent.customDescribe != null && "undefined" != typeof customContent.customDescribe) {
                            dsCustomDescribe = ' value = "' + customContent.customDescribe + '"';
                        } else {
                            dsCustomDescribe = ' value = "" ';
                        }

                        $("#perms").append(
                            '<div  class="layui-form-item">' +
                            '<label class="layui-form-label">' + customContent.customName + '</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="hidden" name="customKeys" value ="' + customContent.customKey + '"/>' +
                            '<input type="hidden" id="customDescribes" name="customDescribes" ' + dsCustomDescribe + '/>' +
                            '<input id="customValues" name="customValues" lay-verify="customValues" placeholder="请输入' + customContent.customName + '"' +
                            'autocomplete="off" class="layui-input" type="text">' +
                            '</div>' +
                            '</div>'
                        );
                    }
                }
                break;
            }
        }
        form.render();
    }

    //分配内容弹出框
    function assignsResource() {
        layui.layer.open({
            title: '资源内容添加',
            type: 2,
            area: ['1000px', '680px'],
            fixed: false, //不固定
            maxmin: true,
            content: '<%=path%>/cms/resource/assignsResource.x'
        });
    }

    function fixAssigns() {
        if ((Array.isArray(commCodes) && commCodes.length == 0)
            || (Object.prototype.isPrototypeOf(commCodes) && Object.keys(commCodes).length == 0)) {
            layer.msg('请选择你需要添加资源的小区', {icon: 5});
            return false;
        }
        var resourceCodes = "";
        for (var i in removeResources) {
            if (resourceCodes != null && resourceCodes.length > 0) {
                resourceCodes += ',';
            }
            resourceCodes += removeResources[i];
        }
        var params = {
            resourceCodes: resourceCodes,
            commCodes: commCodes.join(','),
        };

        postJson("<%=path%>/cms/resource/submitAssignsResource.x", $.param(params), function (data) {
            clearAssignsTab();
            layer.msg('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;分配成功', {icon: 6});
        });
    }

    //去掉资源列表
    var removeResources = [];
    var modelParam = {};
    modelParam.pageSize = 4;

    function queryResourceList(param) {
        if (param.pageSize == null || "undefined" === typeof param.pageSize) {
            param.pageSize = modelParam.pageSize;
        }
        if (param.page == null) {
            param.page = 1;
        }
        postJson("<%=path%>/cms/resource/queryResourceList.x", $.param(param), function (ret) {
            var data = ret.data;
            renderResource(param, data.list);
            layui.laypage({
                cont: param.divPage
                , pages: Math.ceil(data.size / param.pageSize)
                , jump: function (row, first) {
                    if (!first) {
                        param.page = row.curr;
                        queryResourcePage(param);
                    }
                }
            });
        });
    }

    function queryResourcePage(param) {
        postJson("<%=path%>/cms/resource/queryResourceList.x", $.param(param), function (ret) {
            renderResource(param, ret.data.list);
        });
    }

    function renderResource(param, list) {
        $('#' + param.tbody).empty();
        var operation;
        modelParam.list = list;
        for (var i in list) {
            var row = list[i];
            if ('resourceList' === param.tbody) {
                var text;
                if (row.isApproved === "N") {
                    text = ' <span style="color: red">' + row.approvedState + '</span> ';
                } else if (row.isApproved === "Y") {
                    text = ' <span style="color: #00CC66">' + row.approvedState + '</span> ';
                } else {
                    text = ' <span style="color: blue">' + row.approvedState + '</span> ';
                }
                operation = '<tr>' +
                    '<td><div class="center" style="width: 210px;height: 120px; margin-bottom: 8px; border:1px solid #fde7e5; padding: 2px">' +
                    '<img id="icon_url" src=" ' + row.icon_url + ' " style=" max-height: 100%; max-width: 100%;" />' +
                    '</div>' +
                    '</td>' +
                    '<td>' + row.title + '</td>' +
                    '<td>' + row.description + '</td>' +
                    '<td>' + text + '</td>' +
                    '<td><button type="button" onclick="deleteResource(\'' + param.tbody + '\',\'' + param.type_code + '\',' + param.page + ',' + i + ',' + false + ')" ' +
                    'class="permsRemove layui-btn layui-btn-small layui-btn-danger" style="margin-right:20px">删&nbsp;除</button>' +
                    '</td>' +
                    '</tr>';
            } else if ('assignsList' === param.tbody) {
                var checked = 'checked=checked';
                for (var j in removeResources) {
                    if (row.resource_id == removeResources[j]) {
                        checked = '';
                        break;
                    }
                }
                operation = '<tr>' +
                    '<td><div class="center" style="width: 210px;height: 120px; margin-bottom: 8px; border:1px solid #fde7e5; padding: 2px">' +
                    '<img id="icon_url" src=" ' + row.icon_url + ' " style=" max-height: 100%; max-width: 100%;" />' +
                    '</div>' +
                    '</td>' +
                    '<td>' + row.title + '</td>' +
                    '<td>' + row.description + '</td>' +
                    '<td><input type="checkbox" name="selectRemoveResource"  lay-filter="selectRemoveResource" ' + checked + ' value="' + row.resource_id + '"></td>' +
                    '</tr>';
            } else if ('alreadyAssignsList' === param.tbody) {
                operation = '<tr>' +
                    '<td><div class="center" style="width: 210px;height: 120px; margin-bottom: 8px; border:1px solid #fde7e5; padding: 2px">' +
                    '<img id="icon_url" src=" ' + row.icon_url + ' " style=" max-height: 100%; max-width: 100%;" />' +
                    '</div>' +
                    '</td>' +
                    '<td>' + row.title + '</td>' +
                    '<td>' + row.description + '</td>' +
                    '<td><a href="' + row.content_url + '" target="_blank" style="color: blue">' + row.content_url + '</a></td>' +
                    '<td><button type="button" onclick="deleteResource(\'' + param.tbody + '\',\'' + param.type_code + '\',' + param.page + ',' + i + ',' + true + ')" ' +
                    'class="permsRemove layui-btn layui-btn-small layui-btn-danger" style="margin-right:20px">删&nbsp;除</button>' +
                    '</td>' +
                    '</tr>';
            } else if ('checkList' === param.tbody) {
                operation = '<tr>' +
                    '<td><div class="center" style="width: 210px;height: 120px; margin-bottom: 8px; border:1px solid #fde7e5; padding: 2px">' +
                    '<img id="icon_url" src=" ' + row.icon_url + ' " style=" max-height: 100%; max-width: 100%;" />' +
                    '</div>' +
                    '</td>' +
                    '<td>' + row.title + '</td>' +
                    '<td>' + row.description + '</td>' +
                    '<td><a href="' + row.content_url + '" target="_blank" style="color: blue">' + row.content_url + '</a></td>' +
                    '<td>' +
                    '<button type="button" class="layui-btn layui-btn-small layui-btn-normal" onclick="' +
                    'approvedState(\'' + param.type_code + '\',' + param.page + ',' + row.resource_id + ',1)">通过</button>' +
                    '<button type="button" class="layui-btn layui-btn-small layui-btn-danger" onclick="' +
                    'approvedState(\'' + param.type_code + '\',' + param.page + ',' + row.resource_id + ', 2)">打回</button>' +
                    '</td>' +
                    '</tr>';
            }
            $('#' + param.tbody).append(operation);
        }
        form.render();
    }

    function deleteResource(tbody, typeCode, page, row, isNotDeleteOss) {
        var id = modelParam.list[row].resource_id;
        layer.confirm('确定要删除？', {
            btn: ['确定', '取消']
        }, function () {
            postJson("<%=path%>/cms/resource/deleteResource.x", $.param({
                'resource_id': id, 'isNotDeleteOss': isNotDeleteOss
            }), function (data) {
                if ('resourceList' == tbody) {
                    queryResourceList(resourceParam('tab2', typeCode, page));
                } else if ('alreadyAssignsList' == tbody) {
                    queryResourceList(resourceParam('tab4', typeCode, page));
                }
                layer.closeAll();
            });
        });
    }

    function approvedState(typeCode, page, resourceId, i) {
        var param = {};
        param.resource_id = resourceId;
        if (i == 1) {
            layer.confirm('通过审核后，这个资源将可以被展示到客户端。', {
                btn: ['确定', '取消']
            }, function () {
                param.isApproved = "Y";
                param.approvedState = "审核通过";
                postJson("<%=path%>/cms/resource/approvedState.x", $.param(param), function (data) {
                    queryResourceList(resourceParam('tab5', typeCode, page));
                    layer.closeAll();
                });
            });
        } else if (i == 2) {
            layer.open({
                type: 1
                , title: '请输入打回原因'
                , content: '<textarea id="textarea" name="textarea" rows="5" cols="45"></textarea>'
                , btn: ['确定', '取消']
                , btnAlign: 'c' //按钮居中
                , shade: 0 //不显示遮罩
                , yes: function () {
                    param.isApproved = "N";
                    param.approvedState = $("textarea[name='textarea']").val();
                    postJson("<%=path%>/cms/resource/approvedState.x", $.param(param), function (data) {
                        queryResourceList(resourceParam('tab5', typeCode, page));
                        layer.closeAll();
                    });
                }
                , btn2: function () {
                    layer.closeAll();
                }
            });
        }
    }

    function resourceParam(tabIndex, typeCode, page) {
        var param = {};
        param.includeSub = true;
        if (typeCode == null) {
            param.type_code = 'appContent';
        } else {
            param.type_code = typeCode;
        }
        if ('tab2' === tabIndex) {
            param.tbody = 'resourceList';
            param.divPage = 'resourcePage';
        } else if ('tab3' === tabIndex) {
            param.isDefQueryResource = true;
            param.isApproved = 'Y';
            param.type_name = $('#tab3_type_code').val();
            param.tbody = 'assignsList';
            param.divPage = 'assignsPage';
            param.pageSize = 2;
        } else if ('tab4' === tabIndex) {
            var commCode = $('#selectSeparateComm').val();
            typeCode = $('#tab4_type_code').val();
            if (commCode == null || commCode.length <= 0) {
                return;
            }
            if (typeCode === '-1') {
                param.type_code = 'appContent';
            } else {
                param.type_code = typeCode;
            }
            param.isApproved = "Y";
            param.tbody = 'alreadyAssignsList';
            param.divPage = 'alreadyAssignsPage';
            param.commCode = commCode;
        } else if ('tab5' === tabIndex) {
            param.isApproved = "R";
            param.tbody = 'checkList';
            param.divPage = 'checkPage';
        }
        //保证通过之后还是在当前页
        if (page > 1 && modelParam.list.length == 1) {
            param.page = page - 1;
        } else {
            param.page = page;
        }
        return param;
    }

    //添加操作类型
    function addResourceSort() {
        layui.layer.open({
            title: '添加操作类型',
            type: 2,
            area: ['800px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: '<%=path%>/cms/resource/addResourceSort.x?sortName=操作类型&sortCode=appOperationType'
        });
    }

    function getSort(sortCode) {
        var param = {};
        param.sortCode = sortCode;
        param.isPage = false;
        postJson("<%=path%>/cms/resource/queryResourceSortList.x", $.param(param), function (data) {
            var list = data.data.list;
            $('#' + sortCode).empty();
            for (var i in list) {
                $('#' + sortCode).append('<option value="' + list[i].sort_value + '">' + list[i].display_name + '</option>');
            }
            form.render('select');
        });
    }

    function clearRecordTab() {
        $('#type_code').val('-1');
        $('#title').val('');
        $('#description').val('');
        $('#content_url').val('');
        $('#perms').empty();
        LAY_demo_upload.src = '<%=path%>/pic/upload_ioc.png';
        $('#icon_url').val('');
        form.render('select');
    }

    function clearAssignsTab() {
        initCommList(3, '${isCheck}' === 'true');
        removeResources.splice(0, removeResources.length);//清空数组
        $('#assignsList').empty();
    }
</script>
</body>
</html>
